﻿@model PagedList<Pulog.Models.Post>

@{
    Layout = null;
}

<ul id="pagination">
    @{ 
        int splitSize = 10;
        if (Model.PageIndex > splitSize)
        {
           <a class="morePages" href="@Url.Content("~/Posts/Page/")@(Model.PageIndex - splitSize) ">«« Previous @splitSize Pages</a>
        }
        if (ViewData.Model.IsPreviousPage)
        { 
          <li class="next"><a href="@Url.Content("~/Posts/Page/")@(ViewData.Model.PageIndex-1)">« Previous</a></li>
        }
        if (Model.TotalPages > splitSize)
        {
            if (Model.PageIndex.Value > splitSize / 2)
            {
                for (int i = Model.PageIndex.Value - splitSize / 2; i < Model.PageIndex; i++)
                {
                    <li class="morePages"><a href="@Url.Content("~/Posts/Page/")@i">@i</a></li>
                }
            }
            if (Model.PageIndex <= splitSize / 2)
            {
                for (int i = 1; i < Model.PageIndex; i++)
                {
                    <li class="morePages"><a href="@Url.Content("~/Posts/Page/")@i">@i</a></li>
                }
            }
            for (int i = Model.PageIndex.Value; i <= splitSize/2 + Model.PageIndex; i++)
            {
                if (i == ViewData.Model.PageIndex)
                { 
                    <li class="active">@i</li>
                }
                else
                {
                    if (i <= Model.TotalPages)
                    { 
                        <li class="morePages"><a href="@Url.Content("~/Posts/Page/")@i">@i</a></li>
                    }
                }
            }
        }
        if (ViewData.Model.IsNextPage)
        { 
            <li class="next"><a href="@Url.Content("~/Posts/Page/")@(ViewData.Model.PageIndex+1)">Next »</a></li>         
        } 
        if (Model.TotalPages > Model.PageIndex + splitSize)
        { 
            <a class="morePages" href="@Url.Content("~/Posts/Page/")@(Model.PageIndex + splitSize) ">Next @splitSize Pages »»</a>
        }
    }
</ul> 